var gridStore;
 var ids="";
 function openRepeatWindow(){
 	var openWindow = Ext.widget('repeatResourceWindowView');
	openWindow.animateTarget = document.body;
	openWindow.title = "重复导入资源信息";
	openWindow.show();
	var windowGridStore=openWindow.items.items[0].store;
	 windowGridStore.load();
 }
Ext.define('app.controller.ResourceController', {
			extend : 'Ext.app.Controller',
			refs : [{
						ref : 'ViewportResource',
						selector : 'ViewportResource' 
					}],
			stores : ["Resources"],
			init : function() {
				this.control({
							
							'button[name=addSubmit]' : {
								click : function(o) {
									this.onAddOrEditResource(o);
								}
							},'button[name=import]' : {
								click : function(o) {
									this.onOpenImportWindow(o);
								}
							},
							'button[name=import_info]' : {
								click : function(o) {
									Ext.widget('importInfoView', {
													animateTarget : document.body,
													title : "资源导入说明"
												}).show();
								}
							},
							'button[name=add]' : {
								click : function(o) {
									var openWindow = Ext.widget('addResourceView');
									openWindow.animateTarget = document.body;
									openWindow.title = "添加资源";
									openWindow.show();
								}
							}, 
							'button[name=del]' : {
								click : function(o) {
									var rows = o.ownerCt.ownerCt.getSelectionModel().getSelection();// 父组件
									var delIds = "";
									if (rows.length > 0) {
										for (i = 0; i < rows.length; i++) {
											 
											if (i < rows.length - 1) {
												delIds += rows[i].data["id"] + ",";
											} else {
												delIds += rows[i].data["id"];
											}
										}
									} 
									 
									if(delIds!=""){ 
										Ext.Msg.confirm("系统信息", "删除后数据将不可恢复,确定要删除吗", function(btn) {
											if(btn=="yes"){
												Ext.Ajax.request({
													url : "deleteResources.action",
													params : {
														"ids" :delIds
													},
													success : function(respose, option) {
														var result = Ext.decode(respose.responseText);
														Ext.Msg.alert('提示', result.msg);
														gridStore.load();
													},
													failure : function(form, action) {
														Ext.Msg.alert("提示", '出错！');
													}
												});
											}
										});
										
									}else{
										Ext.Msg.alert('提示', "请选择需要删除的资源");
									}
								}
							},
							'button[name=msg_no]' : {
								click : function(o) {
									 o.ownerCt.ownerCt.close();
								}
							}  
						});
			},
			onAddOrEditResource : function(o) {
				var submitFormAdd = o.ownerCt.ownerCt.items.items[0];
				if (!submitFormAdd.getForm().isValid())
					return;
				submitFormAdd.getForm().submit({
							url : 'saveOrupdateResource.action',
							method : 'POST',
							success : function(form, action) {
								var isSuc = action.result;
								Ext.Msg.alert('提示', isSuc.msg);
								gridStore.load();
								o.ownerCt.ownerCt.close();
							},
							failure : function(form, action) {
								var isSuc = action.result;
								Ext.Msg.alert('提示', isSuc.msg);
							}
						});
			},
			onOpenImportWindow : function() {
				Ext.widget('fileUpView', {
							animateTarget : document.body,
							title : "导入资源",
							fileID:0,
							action:'upLoadResource.action'
						}).show();
			},
			onLaunch : function() {
				gridStore=this.getResourcesStore();
				gridStore.on('beforeload', function(store, options) { 
	      			Ext.apply(store.proxy.extraParams, {
	      			ip:Ext.getCmp('ip').getValue()
	      			
	      			});
				});
				gridStore.load();
			}
		});
